//
//  TextFieldViewController.swift
//  CommonTool
//
//  Created by tenroadshow on 12.1.22.
//

import UIKit

class NNTextFieldViewController: NNBaseViewController {

    lazy var textField: UITextField = {
        let textField = UITextField(frame: .zero)
        textField.delegate = self
        textField.backgroundColor = .white
        textField.placeholder = "请输入中文"
        return textField
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .black.withAlphaComponent(0.5)
        
        view.addSubview(textField)
        textField.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.size.equalTo(CGSize(width: 200, height: 40))
        }
        
    }
}

extension NNTextFieldViewController: UITextFieldDelegate {
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        return textField.inputRestrictions(shouldChangeTextIn: range,
                                           replacementText: string,
                                           maxCharacters: 11,
                                           regex: NNRegexType.isChinese.rawValue)
    }
}
